package main

import (
	"fmt"
	"io/ioutil"
	"net/http"
	"regexp"
)

func main() {
	// 发送get请求
	resp, err := http.Get("http://www.zhenai.com/zhenghun/aba")
	if err != nil {
		panic(err)
	}

	defer resp.Body.Close()

	// 判断返回的状态码
	if resp.StatusCode != http.StatusOK {
		fmt.Println("Error:status code", resp.StatusCode)
		return
	}
	all, err := ioutil.ReadAll(resp.Body)

	if err != nil {
		panic(err)
	}

	printCityList(all)
}

func printCityList(contents []byte) {
	// 		<a href="http://www.zhenai.com/zhenghun/aomen" data-v-1573aa7c>中国澳门</a>
	//text := `<a href="(http://www.zhenai.com/zhenghun/[0-9a-z]+)" [^>]*>([^<]+)</a>`
	text := `<a href="(http://album.zhenai.com/u/[0-9]+)" [^>]*>([^<]+)</a>`
	re := regexp.MustCompile(text)
	match := re.FindAllSubmatch(contents, -1)
	for _, m := range match {
		fmt.Printf("City:%s ,URL:%s\n", m[2], m[1])
	}
	fmt.Printf("Matches found : %d\n", len(match))
}
